<?php

function strip_ext($name)
{
  $ext = strrchr($name, '.');
  if($ext !== false) $name = substr($name, 0, -strlen($ext));
  return $name;
} 

function dirList ($directory, $extensions) {
  // create an array to hold directory list
  $results = array();
        
  // create a handler for the directory
  $handler = opendir($directory);
                
  // keep going until all files in directory have been read
  while ($file = readdir($handler)) {
                       
    // if $file isn't this directory or its parent, 
    // add it to the results array
    if ($file != '.' && $file != '..' && !is_dir("$directory/$file")) {
      $ext = end(explode('.', $file));
      if(in_array($ext, $extensions)) $results[] = strip_ext($file);
    }
  }
                                 
  // tidy up: close the handler
  closedir($handler);
                                                                       
  // done!
  return $results;
                                                                                
}

?>                                                                                